import React from 'react';
import CommonList from '../../../components/CommonLists/list';
import { message, Button } from 'antd';
import Modal from '../../../components/Modal/index';
import services from '../../../services/api';
import CaseTrace from './caseTrace';

class List extends CommonList {
  constructor(props) {
    super(props);
    this.api = 'nameList';
    this.detailButton = record => {
      return (
        <Button type='link' onClick={() => props.history.push('/case/task/' + record.case_id + '/detail')}>
          详情
        </Button>
      );
    };
    this.caseTraceButton = record => {
      return (
        <Button type='link' onClick={this.openCaseTrace.bind(this, record.case_id)}>
          案件追踪
        </Button>
      );
    };
    this.btnGroup = [this.detailButton, this.caseTraceButton];
  }

  componentWillMount() {}

  openCaseTrace(id) {
    Modal.open({
      title: '案件追踪',
      width: '500px',
      content: <CaseTrace id={id} />,
      isOkBtn: true,
      isCancelBtn: true,
      ok: () => {
        Modal.close();
      }
    });
  }

  refreshTableFilter = params => {
    this.props.refreshTableFilter && this.props.refreshTableFilter(params);
  };

  delete(record) {
    if (record.strategy_count > 0) {
      message.error(`有${record.strategy_count}条策略使用了此名单，请先下线关联策略再删除此名单！`);
    } else {
      Modal.open({
        title: '',
        isConfirm: true,
        width: '300px',
        content: '确定要删除?',
        isOkBtn: true,
        isCancelBtn: true,
        ok: () => {
          services[this.api].delete(this.getDeleteParam(record)).then(data => {
            if (data.code === 0) {
              message.success(data.msg);
              this.props.queryList();
              Modal.close();
            } else {
              message.error(data.msg);
            }
          });
        },
        cancel: () => {
          Modal.close();
        }
      });
    }
  }
}

export default List;
